﻿@using KPIS.GERP.Models.ICM
@model IEnumerable<KPIS.GERP.Models.ICM.File>

@{
    Layout = "~/Views/Shared/_EmptyLayout.cshtml";
    ViewBag.Title = "เอกสารแนบ";
    ViewBag.Descr = "ข้อมูล" + ViewBag.Title;
    int id = ViewBag.Id;
    int type = ViewBag.Type;
    var files = Model ?? new List<KPIS.GERP.Models.ICM.File>();
    var fileAmount = files.Count();
}

@using (Html.BeginForm())
{
    if(ViewBag.Message  != null)
    {
        <div class="alert alert-block alert-success">
			<button type="button" class="close" data-dismiss="alert">
				<i class="icon-remove"></i>
			</button>
			<i class="icon-ok green"></i>
            @ViewBag.Message
		</div>
    }
    
    @Html.AntiForgeryToken()
    <div class="span12">
	    <div class="widget-main">
		    <div class="row-fluid">
                @if(ViewBag.EmptyLayout!=true)
                {
                    <div class="block-button-menu-above">
                        @Html.ActionLink("เพิ่ม", "Create", new {id = id, type = type}
                                         , new {@class = "btn btn-small btn-success button-standard-width", role = "button"})
                    </div>
                }
                @Html.ValidationSummary(true, "", new { @class = "alert alert-error" })
                <div class="span12" style="margin-top:15px">
                    <p class="text-warning"><strong >
                                                @if(fileAmount > 0)
                                                {
                                                    @:รวม @fileAmount ไฟล์
                                                } else
                                                {
                                                    @: ไม่มีเอกสารแนบ
                                                }
                                            </strong></p>
                    @foreach (var m in files)
                    {                     
                        <div class="alert alert-info">
                            <table style="width:100%">
                                <tr>
                                    <td>
                                        <a href='@Url.Action("StreamFileFromDisk4", new{Id = m.FileId})' class="controls-detail blue" 
                                           style="cursor:pointer; font-weight:bold; font-size: large" 
                                           title='ดาวน์โหลดไฟล์ @m.FileName @(string.IsNullOrWhiteSpace(m.FileDescription) ? "" :"-" + m.FileDescription)'>
                                            <i class="icon-download-alt bigger-120"  title="ดาวน์โหลดไฟล์"></i>&nbsp;&nbsp;
                                            @{var fileName = m.FileName ?? string.Empty;}
                                            @(fileName.Substring(0, Math.Min(fileName.Length, 40)) + (fileName.Length >= 40 ? "..." : ""))
                                        </a> 
                                        <span style="color:silver; font-style:italic; font-size:small">
                                            ดาวน์โหลด: @m.FileDownloadCount,
                                            ขนาดไฟล์: @FileUtility.GetFileSizeHumanReadable(m.FileSizeByte)
                                        </span>
                                    </td>
                                    <td style="width:180px; font-size: small;">
                                        @if(m.CreatedWhen.HasValue)
                                        {
                                            @(m.CreatedWhen.Value.ToLongDateString() + " " + m.CreatedWhen.Value.Hour+ ":" + m.CreatedWhen.Value.Minute+ ":" + m.CreatedWhen.Value.Second)
                                        }
                                    </td>
                                    <td style="width:22px">
                                         @if(ViewBag.EmptyLayout != true)
                                         {
                                             <a href="@Url.Action("Details", new {Id = m.FileId})" title="ดูรายละเอียดไฟล์"><i class="icon-search bigger-120"></i></a>
                                         }
                                    </td>
                                    <td style="width:22px">
                                         @if(ViewBag.EmptyLayout != true)
                                         {
                                             @Html.ActionLink(" ", "Delete", new {id = m.FileId, m.RefType, m.RefId}, new
                                                 {
                                                     @class = "icon-trash bigger-120",
                                                     @style = "color:red; align:right", title = "ลบไฟล์"
                                                 })
                                         }
                                    </td>
                                </tr>
                            </table>

                            
                        </div>
                    }
                </div>
		    </div>
	    </div>
    </div>
}

<style>
    li li { display:inline-block; }
</style>